import { Delete, Get, Post, Put } from "@/http/http";
import { CateForm, CateQuery, CateVO } from "./types";

/**
 * 获取类别下拉列表
 *
 * @param queryParams
 */
export function getCateOptions(): Promise<OptionType[]> {
  return Get("/api/v1/category/options");
}
/**
 * 获取所有类别下拉列表
 *
 * @param queryParams
 */
export function getCateAllOptions(id: any): Promise<OptionType[]> {
  return Get(`/api/v1/category/alloptions/${id}`);
}

/**
 * 获取类别列表
 * @param queryParams
 * @returns
 */
export function listCategories(queryParams: CateQuery): Promise<CateVO[]> {
  return Get("/api/v1/category/page", queryParams);
}

/**
 * 获取菜单表单数据
 *
 * @param id
 */
export function getCateForm(id: number): Promise<CateForm> {
  return Get("/api/v1/category/" + id + "/form");
}

/**
 * 添加菜单
 *
 * @param data
 */
export function addCate(data: CateForm) {
  return Post("/api/v1/category", data);
}

/**
 * 修改菜单
 *
 * @param id
 * @param data
 */
export function updateCate(id: string, data: CateForm) {
  return Put("/api/v1/category/" + id, data);
}

/**
 * 删除菜单
 *
 * @param id 菜单ID
 */
export function deleteCate(id: number) {
  return Delete("/api/v1/category/" + id);
}
